﻿CREATE VIEW [dbo].[vGetCurrentMessageBatches]
AS
SELECT     ISNULL(MessageBatchID, '00000000-0000-0000-0000-000000000000') as MessageBatchID, SUM(CASE WHEN Status = '' THEN 1 ELSE 0 END) AS ProcessedCount, COUNT(ID) AS TotalCount
FROM         dbo.BatchResubmissionMessage
GROUP BY MessageBatchID
HAVING      (SUM(CASE WHEN Status = '' THEN 1 ELSE 0 END) < COUNT(ID))
